package com.xiangge.crawler.inter;

import com.xiangge.config.CrawlerProperties;
import com.xiangge.db.pojo.SynthesizeCategory;
import com.xiangge.db.pojo.SynthesizeGoods;
import com.xiangge.db.repository.SynthesizeCategoryRepository;
import com.xiangge.db.repository.SynthesizeGoodsRepository;
import org.jsoup.nodes.Document;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;

import java.io.IOException;
import java.util.List;


/**
 * @author lsy_server
 */
public abstract class JsoupCrawlerBaseServiceAdaptor implements CrawlerBaseService {
    @Autowired
    protected CrawlerProperties properties;
    @Autowired
    protected SynthesizeGoodsRepository goodsRepository;
    @Autowired
    protected SynthesizeCategoryRepository categoryRepository;

    public Boolean openFlag = true;

    protected JsoupCrawlerBaseServiceAdaptor() {
    }

    public void setOpenFlag(Boolean openFlag) {
        this.openFlag = openFlag;
    }

    @Override
    @Async("taskExecutor")
    public void crawler() {
    }

    @Override
    public String crawlerUrl(String url, Object... param) {
        return String.format(url, param);
    }

    @Override
    public abstract List<SynthesizeGoods> crawlerGoods(String crawlerUrl, Integer page, SynthesizeCategory id) throws IOException;

    @Override
    public abstract List<SynthesizeGoods> analyze(Document document, Integer categoryId);
}
